main();

function main() {
  sleep(1000);
  printInfo();
}

function printInfo() {
  var date = new Date();
  var time = util.format("时间: %d:%d:%d\n", date.getHours(), date.getMinutes(), date.getSeconds());
  var systemInfo = util.format("内存: %d%%\n", getMemoryUsage());
  var appInfo = util.format("包名: %s\n应用名: %s\n活动: %s\n", currentPackage(), app.getAppName(currentPackage()), currentActivity());
  log(time + systemInfo + appInfo);
}

// 获取内存使用率
function getMemoryUsage() {
  var usage = (100 * device.getAvailMem() / device.getTotalMem());
  return Math.round(usage * 100) / 100; // 保留一位小数
}
